//
//  CertDistributionPointName.m
//  TestProject
//
//  Created by 武侠 on 2022/2/18.
//  Copyright © 2022 zhulong. All rights reserved.
//

#import "CertDistributionPointName.h"
#import "CertItemLength.h"
#import "CertTLV.h"

@implementation CertDistributionPointName

- (NSDictionary<NSNumber *,NSString *> *)objectType {
    return @{
        @(0xa0) : @"fullName",
    };
}

/*
30 33(51):          distributionPoint
    A0 5E(94):          [0]: distributionPoint
        A0 5C(92):           [0]fullName
 */
// 根据类型：返回对应的类
- (id _Nullable)getObject:(NSData *)data type:(uint16_t)type {
    if (type == 0xa0) {
        return [[CertGeneralName alloc] initWithData:data];
    }
    return [super getObject:data type:type];
}

+ (BOOL)isValid:(NSData *)data {
    if ([super isValid:data] == NO) {
        return NO;
    }
    char *sdata = (char *)data.bytes;
    if ((uint8_t)sdata[0] != 0x30) {
        return NO;
    }
    
    CertItemLength *length = [[CertItemLength alloc] initWithData:sdata index:0];
    return 1 + length.lenLen < data.length;
}

- (NSString *)description {
    if (self.fullName == nil) {
        return @"无数据";
    }
    
    return [NSString stringWithFormat:@"fullName = \n\t%@", self.fullName.description];
}

@end
